package com.iflytek.uoamp.notify.wechat.format;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.iflytek.uoamp.common.notify.constant.ConfigName;
import com.iflytek.uoamp.common.notify.exception.NotifyException;
import com.iflytek.uoamp.common.notify.obj.Notification;
import com.iflytek.uoamp.common.notify.util.Configurator;

public class FormatFocusWechat extends FixedWechatFormatter {
	
    private static final String FOCUS_PLATFORM_FLAG = "focus_platform_flag";
    
    @Override
    public String pretty(Notification notification, List<?> contents) throws NotifyException {
        StringBuilder builder = new StringBuilder(Configurator.getInstance().getProperty(ConfigName.OPERATION_SMS_TEMPLATE) + "@@");
        builder.append("{\"errorinterface\":\"");

        builder.append(getInterfaceNam(notification));
        builder.append("\",\"operationphone\":\"");
        builder.append(Configurator.getInstance().getProperty(ConfigName.OPERRATION_PHONE));
        builder.append("\"}");

        return builder.toString();
    }


    private String getInterfaceNam(Notification notification) {
        if (notification.getExtend().containsKey(FOCUS_PLATFORM_FLAG)) {
            return StringUtils.defaultString(notification.getExtend().get(FOCUS_PLATFORM_FLAG), "统一运维监控管理平台") + "入口";
        } else {
            return "统一运维监控管理平台";
        }
    }
}
